﻿Imports System.ComponentModel

Partial Public Class SelectImageIdControl
    Implements INotifyPropertyChanged


    Private m_AvailableImages As List(Of MediaFile)

    Public Sub New(ByVal p_AvailableImages As List(Of MediaFile))
        InitializeComponent()
        AvailableImages = p_AvailableImages
        ComboImages.ItemsSource = m_AvailableImages

    End Sub



    Public Property AvailableImages() As List(Of MediaFile)
        Get
            Return m_AvailableImages
        End Get
        Set(ByVal value As List(Of MediaFile))
            m_AvailableImages = value
            NotifyPropertyChanged("AvailableImages")
        End Set
    End Property

    Public ReadOnly Property SelectedImageID() As Integer
        Get
            Return CType(ComboImages.SelectedItem, MediaFile).ID

        End Get
    End Property

    Public ReadOnly Property selectedImagePath() As String
        Get
            Return CType(ComboImages.SelectedItem, MediaFile).Path
        End Get
    End Property

    Private Sub ComboImages_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs)
        NotifyPropertyChanged("selectedImagePath")

        Dim l_imgs As New ImageSourceConverter

        Dim l_ImageSource = CType(l_imgs.ConvertFromString(selectedImagePath), ImageSource)
        ImageBrush1.ImageSource = l_ImageSource
        '    ImageBrush1.ImageSource.SetValue(Image.SourceProperty, l_imgs.ConvertFromString(selectedImagePath))

        

    End Sub

    Public Sub okButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
        DialogResult = True
        RaiseEvent OnOkButtonClick(SelectedImageID)

    End Sub

    Public Delegate Sub OnOkButtonClickDel(ByVal p_selectedImageID As Integer)
    Public Event OnOkButtonClick As OnOkButtonClickDel

    Public Event PropertyChanged As PropertyChangedEventHandler _
      Implements INotifyPropertyChanged.PropertyChanged

    Private Sub NotifyPropertyChanged(ByVal info As String)
        RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
    End Sub


   
   
End Class
